﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace CommonLib.Pattern.FSM
{
	public interface ITransition 
	{
		/// <summary>
		/// Identity
		/// </summary>
		string Key { get; }
		/// <summary>
		/// 优先级
		/// </summary>
		int Priority { get; }
		/// <summary>
		/// 状态转换关闭的状态
		/// </summary>
		IState FromState { get; }
		/// <summary>
		/// 状态转换进入的状态
		/// </summary>
		IState ToState { get; }
		/// <summary>
		/// 当前转换是否是可以进行转换操作
		/// </summary>
		/// <returns></returns>
		bool TransferValid();
		/// <summary>
		/// 转换结束的回调函数
		/// </summary>
		/// <returns></returns>
		bool OnCompleteCallBack();
	}

	public class FSMTransitionBase : ITransition
	{
		public string Key => transitionKey;
		public int Priority => priority;
		public IState FromState => fromState;
		public IState ToState => toState;

		protected string transitionKey = "";
		protected IState fromState;
		protected IState toState;
		protected int priority;

		public FSMTransitionBase(string _key, IState _from, IState _to, int _priority)
		{
			this.transitionKey = _key;
			this.fromState = _from;
			this.toState = _to;
			this.priority = _priority;
		}
		virtual public bool OnCompleteCallBack()
		{
			return true;
		}
		virtual public bool TransferValid()
		{
			return true;
		}
	}
}